import pygame,pygame.locals
import sys,os,time


COLOR_BLACK = (0,0,0)
COLOR_WHITE = (255,255,255)
COLOR_GREEN = (0,255,0)
#COLOR_BKG = COLOR_BLACK

def game_init():
    pygame.init()
    pygame.display.init()

WINDOW_MAX_X = 400
WINDOW_MAX_Y = 400
DISPLAYSURFACE = pygame.display.set_mode((WINDOW_MAX_X,WINDOW_MAX_Y))
DISPLAYSURFACE.fill(COLOR_WHITE)    #   pygame的背景颜色

COLOR_BLOCK_X = 40
COLOR_BLOCK_Y = 40
COLOR_BLOCK_1_POSITION = (200,200)
COLOR_BLOCK_1 = pygame.Surface((COLOR_BLOCK_X,COLOR_BLOCK_Y))
COLOR_BLOCK_1.fill(COLOR_GREEN)
COLOR_BLOCK_1_RECT = COLOR_BLOCK_1.get_rect(center=COLOR_BLOCK_1_POSITION)

SHADOW_BLOCK_1_POSITION = (COLOR_BLOCK_1_POSITION[0]+COLOR_BLOCK_X,COLOR_BLOCK_1_POSITION[1])   #用于掩盖 仅使用COLOR_BLOCK_1_RECT移动时产生的拖影，注意背景颜色。
SHADOW_BLOCK_1 = pygame.Surface((COLOR_BLOCK_X,COLOR_BLOCK_Y))
SHADOW_BLOCK_1.fill(COLOR_BLACK)
SHADOW_BLOCK_1_RECT = SHADOW_BLOCK_1.get_rect(center=SHADOW_BLOCK_1_POSITION)

def COLOR_BLOCK_Move():
    DISPLAYSURFACE.blit(COLOR_BLOCK_1,COLOR_BLOCK_1_RECT)
    DISPLAYSURFACE.blit(SHADOW_BLOCK_1,SHADOW_BLOCK_1_RECT)

    COLOR_BLOCK_1_RECT.move_ip(-5,0)
    SHADOW_BLOCK_1_RECT.move_ip(-5,0)
    if COLOR_BLOCK_1_RECT.right < 0 :
        COLOR_BLOCK_1_RECT.left = WINDOW_MAX_X
        SHADOW_BLOCK_1_RECT.left = WINDOW_MAX_X + COLOR_BLOCK_X
    else :
        pass

if __name__ == "__main__":
    game_init()
    FPS = 60
    while True:
        pygame.time.Clock().tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                sys.exit()

        COLOR_BLOCK_Move()

        pygame.display.update()